package Adapter;

import Commande.Command;
import Moteur.Controler;


public class Adapter implements Ihm{

	private	AdapterMolette adapteurMolette;
	private	AdapterClavier adapteurClavier;
	private Command cmdStart, cmdStop, cmdInc, cmdDec;
	private Controler controler;
	Boolean oldInc=false, oldDec=false;

	public Adapter(){
		adapteurMolette = new AdapterMolette(this);
		adapteurClavier = new AdapterClavier();
	}


	@Override
	public void lireMateriel() {
		adapteurClavier.lireMateriel();
		if(adapteurClavier.getTouchePressed() != 0){
			int bouton = adapteurClavier.getTouchePressed();
			switch (bouton) {
			case 1:
				cmdStart.execute();
				break;
			case 2:
				cmdStop.execute();
				break;
			case 3:
				if(!oldInc){
					oldInc = true;
					cmdInc.execute();
				}
				break;
			case 4:
				if(!oldDec){
					oldDec = true;
					cmdDec.execute();
				}
				break;
			}
		}else{
			oldInc = false;
			oldDec = false;
		}
		adapteurMolette.lireMateriel();
	}

	public void moletteAChange(){
		controler.updateMolette();
	}


	@Override
	public float getValeurMolette() {
		return adapteurMolette.getValeur();
	}


	@Override
	public void setCmdStart(Command cmdStart) {
		this.cmdStart = cmdStart;
	}


	@Override
	public void setCmdStop(Command cmdStop) {
		this.cmdStop = cmdStop;
	}


	@Override
	public void setCmdInc(Command cmdInc) {
		this.cmdInc = cmdInc;
	}


	@Override
	public void setCmdDec(Command cmdDec) {
		this.cmdDec = cmdDec;
	}


	@Override
	public void setControler(Controler controler) {
		this.controler = controler;
	}


}
